﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Linyb.Linq.QueryExtension
{
    public struct BetweenValues
    {
        public object Value1 { get; set; }
        public object Value2 { get; set; }
    }

    public interface IBetweenPredicate : IPredicate
    {
        string PropertyName { get; set; }
        BetweenValues Value { get; set; }
    }

    public class BetweenPredicate<T> : BasePredicate, IBetweenPredicate where T : class
    {
        public override string GetSql(SqlConditionUtil util, IList<object> parameters)
        {
            string columnName = GetColumnName(typeof(T), util, PropertyName);
            string parameterName1 = $"@{parameters.Count}";
            parameters.Add(Value.Value1);
            string parameterName2 = $"@{parameters.Count}";
            parameters.Add(Value.Value2);
            return string.Format("{0}>={1} && {0}<={2}", columnName, parameterName1, parameterName2);
        }

        public BetweenValues Value { get; set; }
    }
}
